import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Dialog {
    id: notificationDialog
    
    property string notificationTitle: ""
    property string notificationMessage: ""
    property int notificationType: 0 // 0: info, 1: success, 2: warning, 3: error
    
    title: notificationTitle
    modal: true
    standardButtons: Dialog.Ok
    
    width: Math.min(400, parent.width * 0.8)
    height: Math.min(200, parent.height * 0.6)
    
    anchors.centerIn: parent
    
    background: Rectangle {
        color: "white"
        border.color: getTypeColor()
        border.width: 2
        radius: 8
    }
    
    function getTypeColor() {
        switch (notificationType) {
            case 1: return "#4CAF50" // success - green
            case 2: return "#FF9800" // warning - orange
            case 3: return "#F44336" // error - red
            default: return "#2196F3" // info - blue
        }
    }
    
    function getTypeIcon() {
        switch (notificationType) {
            case 1: return "✓" // success
            case 2: return "⚠" // warning
            case 3: return "✗" // error
            default: return "ℹ" // info
        }
    }
    
    function getTypeText() {
        switch (notificationType) {
            case 1: return "成功"
            case 2: return "警告"
            case 3: return "错误"
            default: return "信息"
        }
    }
    
    contentItem: ColumnLayout {
        spacing: 15
        
        // 图标和类型
        RowLayout {
            Layout.fillWidth: true
            spacing: 10
            
            Rectangle {
                width: 40
                height: 40
                radius: 20
                color: getTypeColor()
                
                Text {
                    anchors.centerIn: parent
                    text: getTypeIcon()
                    font.pixelSize: 20
                    font.bold: true
                    color: "white"
                }
            }
            
            Text {
                text: getTypeText()
                font.pixelSize: 16
                font.bold: true
                color: getTypeColor()
            }
            
            Item {
                Layout.fillWidth: true
            }
        }
        
        // 消息内容
        ScrollView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            
            Text {
                text: notificationMessage
                font.pixelSize: 14
                color: "#212121"
                wrapMode: Text.WordWrap
                width: parent.width
            }
        }
    }
    
    function show(title, message, type) {
        notificationTitle = title
        notificationMessage = message
        notificationType = type || 0
        open()
    }
    
    // 自动关闭定时器（仅对成功和信息类型）
    Timer {
        id: autoCloseTimer
        interval: 3000
        running: notificationDialog.visible && (notificationType === 0 || notificationType === 1)
        onTriggered: notificationDialog.close()
    }
}